﻿using System.ComponentModel;
using Slippor.Common.PluginFramework;
using Slippor.Douban.Radio.Tracker;
using System.Windows.Forms;
using Slippor.Douban.Radio.BaseForm;

namespace LocalTrackerData
{
    [Description("本地听歌历史记录")]
    [DisplayName("本地历史记录")]
    [Author("拖鞋不脱")]
    [Version(typeof(LocalTrackerVersion), "1.0.0.0")]
    [PluginCategory(PluginCategory.Tracker)]
    public class LocalTrackerPlugin : TrackerPlugin
    {
        private ToolStripMenuItem toolStripItem = new ToolStripMenuItem("历史记录")
        {
            
        };

        TrackForm _trackForm;
        public LocalTrackerPlugin()
        {
            toolStripItem.DropDownItems.Add(new ToolStripMenuItem("查看报表", null, (send, e) =>
                {
                    if (_trackForm == null || _trackForm.IsDisposed)
                    {
                        _trackForm = new TrackForm();
                        _trackForm.SetFav += ((DoubanForm)_application).MakeFav;
                    }
                    _trackForm.Show();
                    if(_trackForm.WindowState == FormWindowState.Minimized)
                    {
                        _trackForm.WindowState = FormWindowState.Normal;
                    }
                    _trackForm.Activate();
                    _trackForm.BringToFront();
                })
                {
                    AutoSize = true,
                    DisplayStyle = ToolStripItemDisplayStyle.Text
                });
            Loaded += new System.EventHandler(LocalTrackerPlugin_Loaded);
            UnLoaded += new System.EventHandler(LocalTrackerPlugin_UnLoaded);
        }

        private void LocalTrackerPlugin_UnLoaded(object sender, System.EventArgs e)
        {
            _application.RemoveToolStripItem(toolStripItem);
        }

        private void LocalTrackerPlugin_Loaded(object sender, System.EventArgs e)
        {
            _application.AddToolStripItem(toolStripItem);
        }

        private static readonly ITracker _tracker = new LocalTracker();
        protected override ITracker Tracker
        {
            get { return _tracker; }
        }
    }
}